import { getMemberAddressAPI } from "@/services/address";
import type { AddressItem } from "@/types/address";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useAddressStore = defineStore("address", () => {
  const selectedAddress = ref<AddressItem>();
  const addressList = ref<AddressItem[]>([]);

  const getMemberAddressData = async () => {
    const res = await getMemberAddressAPI();
    addressList.value = res.result
  }

  const changeSelectedAddress = (val:AddressItem) => {
    selectedAddress.value = val;
  }

  return {
    addressList,
    selectedAddress,
    changeSelectedAddress,
    getMemberAddressData
  }
})